home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snpd0492.zip / DRVALID.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  2KB  |  86 lines

  1. /*
  2. **  DRVALID.C - validate disk drives
  3. **
  4. **  Original Copyright 1988-1991 by Bob Stout as part of
  5. **  the MicroFirm Function Library (MFL)
  6. **
  7. **  This subset version is functionally identical to the
  8. **  version originally published by the author in Tech Specialist
  9. **  magazine and is hereby donated to the public domain.
  10. */
  11.  
  12. #include <dos.h>
  13. #include <stdlib.h>
  14.  
  15. typedef enum {ERROR = -1, SUCCESS, FALSE = 0, TRUE} LOGICAL;
  16.  
  17. /*
  18. **  getdrv()
  19. **
  20. **  Just as getcwd() returns the default directory, getdrv() returns
  21. **  the current drive.
  22. **
  23. **  Arguments: None.
  24. **
  25. **  Returns:   Current drive (0 = A:, 1 = B:, etc.)
  26. **
  27. **  Side effects: none
  28. */
  29.  
  30. int getdrv(void)
  31. {
  32.       union REGS regs;
  33.  
  34.       regs.h.ah = 0x19;
  35.       intdos(®s, ®s);
  36.       return (regs.h.al);
  37. }
  38.  
  39. /*
  40. **  chdrv()
  41. **
  42. **  Like chdir(), except changes drives rather than directories.
  43. **
  44. **  Arguments: 1 - target drive (0 = A:, 1 = B:, etc.)
  45. **
  46. **  Returns: SUCCESS or ERROR
  47. **
  48. **  Side effects: none
  49. */
  50.  
  51. LOGICAL chdrv(int drive)
  52. {
  53.       union REGS regs;
  54.  
  55.       regs.h.ah = 0x0e;
  56.       regs.h.dl = (char)drive;
  57.       intdos(®s, ®s);
  58.       if (drive != getdrv())
  59.             return ERROR;
  60.       else  return SUCCESS;
  61. }
  62.  
  63. /*
  64. **  drvalid()
  65. **
  66. **  Verifies whether a logical disk drive is available without
  67. **  triggering the DOS critical error handler.
  68. **
  69. **  Arguments: 1 - target drive (0 = A;, 1 = B:, etc.)
  70. **
  71. **  Returns:   TRUE  - drive is valid
  72. **             FALSE - drive is invalid
  73. **
  74. **  Side effects: none
  75. */
  76.  
  77. LOGICAL drvalid(int drive)
  78. {
  79.       int original, result;
  80.  
  81.       original = getdrv();
  82.       result   = (SUCCESS == chdrv(drive));
  83.       chdrv(original);
  84.       return result;
  85. }
  86.